home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d17 / pset.arc / PSET.C < prev    next >
Text File  |  1988-05-05  |  12KB  |  412 lines

  1. /*
  2.  *    **************************************************
  3.  *    *                                                *
  4.  *    *                                                *
  5.  *    *         PSET - Printer setup utility           *
  6.  *    *                                                *
  7.  *    *                    for the                     *
  8.  *    *                                                *
  9.  *    *              IBM Graphics printer              *
  10.  *    *                                                *
  11.  *    *              Version 2.2 04-24-88              *
  12.  *    *                                                *
  13.  *    *              Judson D. McClendon               *
  14.  *    *                 P.O. Box 9946                  *
  15.  *    *              Birmingham, AL 35220              *
  16.  *    *                 205-853-8440                   *
  17.  *    *            Compuserve [74415,1003]             *
  18.  *    *                                                *
  19.  *    *                                                *
  20.  *    *          Use:  PSET opt opt opt ...            *
  21.  *    *                                                *
  22.  *    *                                                *
  23.  *    *       The options are in the table below.      *
  24.  *    *      The program ignores unknown options.      *
  25.  *    *        Change the option names or setup        *
  26.  *    *          strings to suit your printer.         *
  27.  *    *      Be sure to use lower case key names       *
  28.  *    *        in the table and end each setup         *
  29.  *    *          string entry with a hex FF.           *
  30.  *    *                                                *
  31.  *    *       Use the printer reset function for       *
  32.  *    *         your C compiler in the Reset()         *
  33.  *    *         function below.  Functions for         *
  34.  *    *        both MSC & Turbo C are included.        *
  35.  *    *                                                *
  36.  *    *                                                *
  37.  *    **************************************************
  38.  */
  39.  
  40.  
  41.  
  42. /*
  43.  *    **************************************************
  44.  *    *                                                *
  45.  *    *                   Includes                     *
  46.  *    *                                                *
  47.  *    **************************************************
  48.  */
  49.  
  50. #include <bios.h>
  51. #include <conio.h>
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54. #include <string.h>
  55.  
  56.  
  57.  
  58. /*
  59.  *    **************************************************
  60.  *    *                                                *
  61.  *    *                   Constants                    *
  62.  *    *                                                *
  63.  *    **************************************************
  64.  */
  65.  
  66. #define TRUE 1
  67. #define FALSE 0
  68. #define BOOLEAN int
  69. #define MAXLINES 20
  70. #define PARMSPERPAGE (MAXLINES * 2)
  71. #define LEFTSIDE 0
  72. #define RIGHTSIDE 40
  73.  
  74.  
  75.  
  76. /*
  77.  *    **************************************************
  78.  *    *                                                *
  79.  *    *             Function Declarations              *
  80.  *    *                                                *
  81.  *    **************************************************
  82.  */
  83.  
  84. void main(int argc, char *argv[]);
  85. void ShowPage(int begin, int nbrparms);
  86. void ClearWork(void);
  87. void Execute(char *parm, char *str);
  88. void Reset(char *parm);
  89. void DisplayParm(char *parm);
  90.  
  91.  
  92.  
  93. /*
  94.  *    **************************************************
  95.  *    *                                                *
  96.  *    *           Global Variable Definition           *
  97.  *    *                                                *
  98.  *    **************************************************
  99.  */
  100.  
  101. char
  102.    header1[] = "Setup 2.1 for IBM Graphics printer\n"
  103.                " Usage: PSET opt opt opt ..."
  104.                "   where opt is any of the following options:",
  105.    header2[] = "    OPTION  FUNCTION                        OPTION  FUNCTION",
  106.    line[80];
  107.  
  108.  
  109.  
  110. /*
  111.  *    **************************************************
  112.  *    *                                                *
  113.  *    *                Parameter Table                 *
  114.  *    *                                                *
  115.  *    **************************************************
  116.  */
  117.  
  118. static struct {
  119.    char *key, *data, *desc;
  120.    } table[] = {
  121.  
  122.                   /* Common Functions */
  123.  
  124.       {"lf",         "\x00a\x0ff",           "Line Feed"},
  125.       {"ff",         "\x00c\x0ff",           "Form Feed"},
  126.       {"cr",         "\x00d\x0ff",           "Carriage Return"},
  127.       {"page",       "\x00d\x00c\x0ff",      "Page Eject"},
  128.       {"bell",       "\x007\x0ff",           "Sound Alarm"},
  129.       {"can",        "\x018\x0ff",           "Clear Buffer"},
  130.       {"reset",      "\x0ff",                "Reset Printer"},
  131.       {"","",""},
  132.  
  133.                   /* Character Spacing */
  134.  
  135.       {"10cpi",      "\x012\x0ff",           "10 Chars Per Inch"},
  136.       {"12cpi",      "\x01b\x03a\x0ff",      "12 Chars Per Inch"}, 
  137.       {"15cpi",      "\x01b\x01f9\x0ff",     "15 Chars Per Inch"}, 
  138.       {"16cpi",      "\x00f\x0ff",           "16 Chars Per Inch"}, 
  139.       {"17cpi",      "\x00f\x0ff",           "17.1 Chars Per Inch"}, 
  140.       {"","",""},
  141.  
  142.                   /* Line Spacing */
  143.  
  144.       {"6lpi",       "\x01b3\x024\x0ff",     "6 Lines Per Inch"},
  145.       {"8lpi",       "\x01b3\x01b\x0ff",     "8 Lines Per Inch"},
  146.       {"skip",       "\x01bN\x002\x0ff",     "Skip Perf"}, 
  147.       {"noskip",     "\x01bO\x0ff",          "Don't Skip Perf"},
  148.       {"","",""},
  149.  
  150.                   /* Character Attributes */
  151.  
  152.       {"exp",        "\x01bW\x001\x0ff",     "Set Expanded Print"},
  153.       {"noexp",      "\x01bW\x000\x0ff",     "Reset Expanded Print"},
  154.       {"emph",       "\x01bE\x0ff",          "Set Emphasized Print"},
  155.       {"noemph",     "\x01bF\x0ff",          "Reset Emphasized Print"},
  156.       {"enh",        "\x01bG\x0ff",          "Set Enhanced Print"},
  157.       {"noenh",      "\x01bH\x0ff",          "Reset Enhanced Print"},
  158.       {"","",""},
  159.  
  160.                   /* Character Sets */
  161.  
  162.       {"set1",       "\x01b7\x0ff",          "Character Set 1"},
  163.       {"set2",       "\x01b6\x0ff",          "Character Set 2"},
  164.  
  165.       {"\x0ff"}      /* Table End Marker: Do not remove! */
  166.    };
  167.  
  168.  
  169.  
  170. /*
  171.  *    **************************************************
  172.  *    *                                                *
  173.  *    *                     Main                       *
  174.  *    *                                                *
  175.  *    **************************************************
  176.  */
  177.  
  178. void main(int argc, char *argv[])
  179.  
  180. {
  181.  
  182.    BOOLEAN
  183.       goodparms = FALSE;
  184.    int
  185.       nbrparms = 0,
  186.       parnum,
  187.       i;
  188.    char
  189.       *parm;
  190.  
  191.  
  192.    for (parnum = 1; parnum < argc; parnum++) {        /* Decode Options */
  193.  
  194.       parm = argv[parnum];
  195.       strlwr(parm);
  196.  
  197.       if (! strcmp(parm, "reset")) {
  198.          Reset(parm);
  199.          goodparms = TRUE;
  200.          }
  201.  
  202.       else {
  203.  
  204.          for (i = 0; table[i].key[0] != '\x0ff'; i++) {
  205.  
  206.             if (! strcmp(parm, table[i].key) ) {
  207.                Execute(parm, table[i].data);
  208.                goodparms = TRUE;
  209.                break;
  210.                }
  211.  
  212.             }  /* for */
  213.  
  214.          }  /* else */
  215.  
  216.       }  /* for */
  217.  
  218.  
  219.    if (! goodparms) {
  220.  
  221.       puts(header1);
  222.       puts(header2);
  223.  
  224.       nbrparms = 0;
  225.       for (i = 0; table[i].key[0] != '\x0ff'; i++) {  /* Count Parameters */
  226.          nbrparms++;
  227.          }
  228.  
  229.       for (i = 0; i < nbrparms; i += PARMSPERPAGE) {
  230.          if (i) {
  231.             fputs("Press a key to continue...", stdout);
  232.             getch();
  233.             putch('\r');
  234.             fputs("                           ", stdout);
  235.             putch('\r');
  236.             }
  237.  
  238.          ShowPage(i, nbrparms);
  239.  
  240.          }  /* for */
  241.  
  242.       }  /* if */
  243.  
  244. }
  245.  
  246.  
  247.  
  248. /*
  249.  *    **************************************************
  250.  *    *                                                *
  251.  *    *                  Show Page                     *
  252.  *    *                                                *
  253.  *    **************************************************
  254.  */
  255.  
  256. void ShowPage(int begin, int nbrparms)
  257.  
  258. {
  259.  
  260.    int
  261.       lx, lend,
  262.       rx, rend,
  263.       shift, size;
  264.  
  265.  
  266.    lx = begin;
  267.  
  268.    if ((rend = begin + PARMSPERPAGE) > nbrparms)
  269.       rend = nbrparms;
  270.  
  271.    rx = (lx + rend + 1) / 2;
  272.    lend = rx;
  273.  
  274.    if (! *table[lx].key)
  275.       lx++;
  276.  
  277.    if (! *table[rx].key)
  278.       rx++;
  279.  
  280.    while (lx < lend) {
  281.  
  282.       ClearWork();
  283.  
  284.       if (lx < lend) {                        /* Left side */
  285.          size = strlen(table[lx].key);
  286.          if (size > 10)
  287.             size = 10;
  288.          shift = 10 - size;
  289.          strncpy(&line[LEFTSIDE + shift], table[lx].key, size);
  290.          if (size)
  291.             line[LEFTSIDE + size + shift] = ':';
  292.          size = strlen(table[lx].desc);
  293.          if (size > 25)
  294.             size = 25;
  295.          strncpy(&line[LEFTSIDE + 12], table[lx].desc, size);
  296.          lx++;
  297.          }
  298.  
  299.       if (rx < rend) {                        /* Right side */
  300.          size = strlen(table[rx].key);
  301.          if (size > 10)
  302.             size = 10;
  303.          shift = 10 - size;
  304.          strncpy(&line[RIGHTSIDE + shift], table[rx].key, size);
  305.          if (size)
  306.             line[RIGHTSIDE + size + shift] = ':';
  307.          size = strlen(table[rx].desc);
  308.          if (size > 25)
  309.             size = 25;
  310.          strncpy(&line[RIGHTSIDE + 12], table[rx].desc, size);
  311.          rx++;
  312.          }
  313.  
  314.       puts(line);                             /* Print line */
  315.  
  316.       }  /* while */
  317.  
  318. }
  319.  
  320.  
  321.  
  322. /*
  323.  *    **************************************************
  324.  *    *                                                *
  325.  *    *                  Clear Work                    *
  326.  *    *                                                *
  327.  *    **************************************************
  328.  */
  329.  
  330. void ClearWork(void)
  331.  
  332. {
  333.  
  334.    int i = 0;
  335.  
  336.  
  337.    while (i < 79)
  338.       line[i++] = ' ';
  339.  
  340.    line[79] = '\0';
  341.  
  342. }
  343.  
  344.  
  345.  
  346. /*
  347.  *    **************************************************
  348.  *    *                                                *
  349.  *    *                    Execute                     *
  350.  *    *                                                *
  351.  *    **************************************************
  352.  */
  353.  
  354. void Execute(char *parm, char *str)
  355.  
  356. {
  357.  
  358.    while(*str != '\x0ff') {
  359.       fputc(*str, stdprn);
  360.       str++;
  361.       }
  362.  
  363.    DisplayParm(parm);
  364.  
  365. }
  366.  
  367.  
  368.  
  369. /*
  370.  *    **************************************************
  371.  *    *                                                *
  372.  *    *                 Reset Printer                  *
  373.  *    *                                                *
  374.  *    **************************************************
  375.  */
  376.  
  377. void Reset(char *parm)
  378.  
  379. {
  380.  
  381.    _bios_printer(_PRINTER_INIT, 0, NULL);    /* Reset LPT1: (Microsoft) */
  382.  
  383. /*
  384.  *   Reset LPT1: for Turbo C
  385.  *
  386.  * biosprint(1, 0, 0);
  387.  *
  388.  */
  389.  
  390.    DisplayParm(parm);
  391.  
  392. }
  393.  
  394.  
  395.  
  396. /*
  397.  *    **************************************************
  398.  *    *                                                *
  399.  *    *              Display Parameter                 *
  400.  *    *                                                *
  401.  *    **************************************************
  402.  */
  403.  
  404. void DisplayParm(char *parm)
  405.  
  406. {
  407.  
  408.    fputs(parm, stdout);
  409.    fputc(' ', stdout);
  410.  
  411. }
  412.